import Vue from 'vue'
import Vuex from 'vuex'
import login from "./canyao/login"
Vue.use(Vuex)
import avatarUrl from "@/assets/upload/users.jpg";
import {
  userApi
} from "@/http/api.js";
export default new Vuex.Store({
  state: {
    headerShow: false,
    loginOfNot: false,
    avatarUrl: avatarUrl,
    userData: [],
    fllows: "",
    followeds: "",
    nickname: "",
    eventCount: "",
    // 歌单分类
    cat: "全部",
    songList: [],
    audioKey:0,
  },
  mutations: {
    // 登录获取用户信息
    isLogin(state) {
      // string id正确
      const userId = localStorage.getItem("userId");
      if (userId) {
        userApi(userId).then((res) => {
          console.log(res);
          console.log(userId);
          console.log(state.headerShow);
          console.log(res.code);
          if (res.code === 200) {
            // this.$route.push("/");
            state.headerShow = true;
            state.loginOfNot = true,
              state.avatarUrl = res.profile.avatarUrl;
            state.userData = res
            state.fllows = res.profile["follows"]
            state.followeds = res.profile["followeds"]
            state.nickname = res.profile["nickname"]
            state.eventCount = res.profile.eventCount

          }
        });
      }
    },
    // 改变分类
    changeCate(state, payload) {
      state.cat = payload
    },
    setSongList(state, payload) {
      state.songList.unshift(payload);
      localStorage.setItem('songList',JSON.stringify(state.songList));
    },
    // 强制播放条刷新
    refAudio(state){
      state.audioKey++
    },
    // 播放
  },
  actions: {},
  modules: {
    login
  }
})